package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.graphics.Rect;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.swgk.core.util.DisplayUtil;
import com.swgk.core.util.ScreenUtil;


/**
 * Created by WYJ on 2020/8/27.
 */
public class MyItemDecoration extends RecyclerView.ItemDecoration {

    private int mSpaceSize;
    private boolean isBottom;
    private Context mContext;

    public MyItemDecoration() {
        mSpaceSize = 10;
    }

    public MyItemDecoration(Context context) {
        this.mContext = context;
        mSpaceSize = 10;
    }

    public MyItemDecoration(boolean bottom) {
        mSpaceSize = 10;
        this.isBottom = bottom;
    }

    public MyItemDecoration(int spaceSize) {
        mSpaceSize = spaceSize;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {

        int position = parent.getChildLayoutPosition(view);
        if (mContext != null){
            if (isBottom) {
                if (position == 0) {
                    outRect.set(0, 0, 0, 0);
                } else {
                    outRect.set(0, 0, 0, DisplayUtil.dip2px(mContext,mSpaceSize));
                }
            } else {
                outRect.set(0, 0, DisplayUtil.dip2px(mContext,mSpaceSize), DisplayUtil.dip2px(mContext,mSpaceSize));
            }
        }else {
            if (isBottom) {
                if (position == 0) {
                    outRect.set(0, 0, 0, 0);
                } else {
                    outRect.set(0, 0, 0, ScreenUtil.dip2px(mSpaceSize));
                }
            } else {
                outRect.set(0, 0, ScreenUtil.dip2px(mSpaceSize), ScreenUtil.dip2px(mSpaceSize));
            }
        }
    }
}
